package com.shujia.core;

import java.io.Serializable;

public class Demo14Thread {
    public static void main(String[] args) {


        //创建线程对象
        MyThread myThread = new MyThread();
        //启动线程
        new Thread(myThread).start();


        for (int i = 0; i < 10; i++) {
            System.out.println("main 第" + (i + 1) + "次打印");

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }

}

//线程Serializable接口  标记类的对象可以序列化

class MyThread implements Runnable, Serializable {


    //线程启动之后执行的逻辑
    public void run() {

        for (int i = 0; i < 10; i++) {
            System.out.println("MyThread 第" + (i + 1) + "次打印");

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

    }
}
